// app.js
import {utils} from './utils/util.js';
import {config} from './utils/config.js';
import {kuoqi} from './utils/kuoqi.js';
import {kapp} from './kuoqi/index.js';
// wx.checkSession;;检查登录态是否过期：调用成功说明当前 session_key 未过期，调用失败说明 session_key 已过期
// wx.getUserProfile(Object object)
App({
  onLaunch() {
    var ths = this;
    // 展示本地存储能力
    // const logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)
    //wx.login初始化用户基础登录
    //用户基础的信息的初始化
    wx.login({
        success: res => {
            kuoqi.ajax({
                url:'/Api/WxApplet/fastregister',
                dataType:'json',
                type:'post',
                data:{
                    code:res.code,
                },
                success:function(rs){
                  if(rs.status){
                    //将参数放到storage中
                    for(let i in rs.data){
                      wx.setStorageSync(i, rs.data[i]);
                    }
                    //wx.setStorageSy(rs.data);
                    //config.setDatas(rs.data);
                  }
                }
              })
        }
    });
    // 登录
    wx.login({
      success: res => {
        kuoqi.ajax({
          url:'/Api/WxApplet/Config',
          dataType:'json',
          type:'post',
          success:function(rs){
            if(rs.status){
              //将参数放到storage中
              for(let i in rs.data){
                wx.setStorageSync(i, rs.data[i]);
              }
              //wx.setStorageSy(rs.data);
              //config.setDatas(rs.data);
            }
          }
        })
      }
    })

    //重置页面的顶部胶囊的相关信息
    let systemInfo = wx.getSystemInfoSync();
    this.globalData.navbar.statusBarHeight = systemInfo.statusBarHeight;//状态bar的装改开始的高度
    if (wx.getMenuButtonBoundingClientRect) {
      let navbar = wx.getMenuButtonBoundingClientRect();
      this.globalData.navbar.height = navbar.bottom + navbar.top - systemInfo.statusBarHeight + (systemInfo.screenWidth - navbar.right) / 2;
      this.globalData.navbar.left = systemInfo.screenWidth - navbar.right;
      //配置页面显示区域
      //console.log(this.globalData.navbar);
    }
  },

  //配置信息基础
  config:config,
  //特定功能信息
  kuoqi:kuoqi,
  kapp:kapp,
  
  //公共数据区域
  globalData: {
    userInfo: null,
    icon:config.icons,
    token:'',//基础的token信息
    navbar:{
      statusBarHeight:0,
      height:0,
      left:0,
    },
    //custom:wx.getMenuButtonBoundingClientRect(),
  }
})
